package com.sillyhat.optimize.chapter.two.AvoidNewInstance.error;

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * 2.5  避免创建不必要的对象
 *
 * @author 徐士宽
 * @date 2017/1/13 10:49
 */
public class AvoidNewInstanceError {

    //校验某日期是否处于数字年份之间
    public boolean isBabyBoomer(Date birthday,int beginYear,int endYear){
        Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        gmtCal.set(beginYear,Calendar.JANUARY,1,0,0,0);
        Date boomStart = gmtCal.getTime();
        gmtCal.set(endYear,Calendar.JANUARY,1,0,0,0);
        Date boomEnd = gmtCal.getTime();
        return birthday.compareTo(boomStart) >= 0 && birthday.compareTo(boomEnd) < 0;
    }

}
